<!--组别管理-->

#include('head.html')
	</head>
#if(page>groups.totalPages)
<script>
	window.location.href="/backstage/group?key=${search}&page=${groups.totalPages}";
</script>
#end
	<body>
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">组别管理</strong><small></small></div>
			</div>

			<hr>

			<div class="am-g">
				<div class="am-u-sm-12 am-u-md-6">
					<div class="am-btn-toolbar">
						<div class="am-btn-group am-btn-group-xs">
							#if(search=="")
							<button type="button" class="am-btn am-btn-default addbtn"><span class="am-icon-plus"></span> 新增</button>
							#else
							<button type="button" class="am-btn am-btn-default" onclick="location.href='/backstage/group'">
								<span class="am-icon-chevron-left"></span> 返回
							</button>
							#end

							<button type="button"  style="display:none;" class="am-btn am-btn-default am-btn-xs am-text-success morecheck gleader">
								<span class="am-icon-calendar"></span> 历届组长
							</button>
							<button type="button" style="display:none;" class="am-btn am-btn-default am-text-danger morecheck deleteMore">
								<span class="am-icon-trash-o"></span> 删除
							</button>
						</div>
					</div>
				</div>
				<div class="am-u-sm-12 am-u-md-3">

				</div>
				<div class="am-u-sm-12 am-u-md-3">
					<div class="am-input-group am-input-group-sm">
						<input type="text" style="color:red;" placeholder="请输入组名关键字" id="con" class="am-form-field" value="${search}">
						<span class="am-input-group-btn">
           					<button type="button" class="am-btn am-btn-default search" type="button">搜索</button>
          				</span>
					</div>
				</div>
			</div>
			<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form">
						<input type="hidden" name="ids" id="ids">
						<table class="am-table am-table-striped am-table-hover table-main">
							<thead>
								<tr>
									<th class="table-check"><input class="chooseall" type="checkbox"></th>
									<th class="table-id am-hide-sm-only">ID</th>
									<th class="table-title">组名</th>
									<th class="table-title">组长</th>
									<th class="table-headman am-hide-sm-only">组长ID</th>
									<th class="table-set">操作</th>
								</tr>
							</thead>
							<tbody>
							#set(i=0)
							#for(Group group : groups.getRows())
								<tr>
									<td><input type="checkbox" name="checkbox" value="${group.g_id}"></td>
									<td class="am-hide-sm-only">${group.g_id}</td>
									<td>
										<a onclick="editGroup(${group.g_id})">${group.g_gname}</a>
									</td>
									<td>
										<a onclick="member(${group.g_leader})">${member[i].m_realname}</a>
									</td>
									<td class="am-hide-sm-only">${group.g_leader}</td>
									<td>
										<div class="am-btn-toolbar">
											<div class="am-btn-group am-btn-group-xs">
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="editGroup(${group.g_id})"><span class="am-icon-pencil-square-o"></span> 编辑</button>
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-success am-hide-sm-only" onclick="location.href='gleader/${group.g_id}'"><span class="am-icon-calendar"></span> 历届组长</button>
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only deleteThis"><span class="am-icon-trash-o"></span> 删除</button>
											</div>
										</div>
									</td>
								</tr>
							#set(i=i+1)
							#end
							#if(i==0)
							<tr><td class="am-hide-sm-only"></td><td></td><td></td><td>暂无记录！</td><td></td><td class="am-hide-sm-only"></td></tr>
							#end
							</tbody>
						</table>
						<div class="am-cf">
							共 ${groups.getTotalRows()} 条记录
							#if(search!="")(查询结果）
							#end
							<div class="am-fr">
								<ul class="am-pagination">
									<li class="${groups.isHasPrevPage()  ? '':'am-disabled'}">
										<a href="/backstage/group?key=${search}&page=${groups.getPrevPage()}">«</a>
									</li>
									#set(j=groups.getPageNum()-(groups.getPageNum()%5!=0?groups.getPageNum()%5:5)+1)
									#for(i : range(j, (j+4) > groups.totalPages ? groups.totalPages : j+4))
									<li class="${i == groups.pageNum  ? 'am-active':''}">
										<a href="/backstage/group?key=${search}&page=${i}">${i}</a>
									</li>
									#end
									<li class="${groups.isHasNextPage()  ? '':'am-disabled'}">
										<a href="/backstage/group?key=${search}&page=${groups.getNextPage()}">»</a>
									</li>
								</ul>
							</div>
						</div>
						<hr>
					</form>
				</div>

			</div>
		</div>
		#include('/backstage/footer.html')
		<script type="text/javascript" src="/static/js/backstage/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="/static/js/backstage/choose.js" ></script>
		<script type="text/javascript" src="/static/js/backstage/plugs.js" ></script>
	    <script>
            function editGroup(id){
                $.jq_Panel({
                    title: "编辑组别",
                    iframeWidth: 500,
                    iframeHeight: 360,
                    url: "editGroup/"+id
                });
			}
			function member(id){
                window.parent.$.jq_Panel({
                    title: "成员信息",
                    iframeWidth: 700,
                    iframeHeight: 500,
                    url: "/users/"+id
                });
			}
			function check(){
				var checkID = [];//定义一个空数组
				$("input[name='checkbox']:checked").each(function(j){//把所有被选中的复选框的值存入数组
					 checkID[j] =$(this).val();
				});
				$("#ids").val(checkID);
			}

		$(function() {

			$(".addbtn").click(function() {
				$.jq_Panel({
                    title: "添加组别",
                    iframeWidth: 500,
                    iframeHeight: 360,
                    url: "addGroup"
                });
			});

			$(".search").click(function(){
			    window.location.href="/backstage/group?key="+$("#con").val()+"&page=1";
			});

			$(".gleader").click(function(){
				var id = $("input[name='checkbox']:checked").val();
				window.location.href="/backstage/gleader/"+id;
			});

			$(".deleteThis").click(function() {
					if(confirm('确定删除吗？')){
						$("#ids").val($(this).parents("tr").find("input[name='checkbox']").val());
			        	$.ajax({
							url:"/backstage/group_delete",
							dataType:"json",
							type:"post",
							data:$("form").serialize(),
							success:function(result){
								alert("删除成功！");
								window.location.href=location.href;
							},
							error:function(result){
              				  	alert("系统繁忙！");
           					 }
						});
						<!--$(this).parents("tr").remove();-->
					}
			});
			$(".deleteMore").click(function() {
					if(confirm('确定删除吗？')){
						check();
        				$.ajax({
							url:"/backstage/group_delete",
							dataType:"json",
							type:"post",
							data:$("form").serialize(),
							success:function(result){
								alert(result.tips+"条记录删除成功！");
								window.location.href=location.href;
							},
							error:function(result){
              				  	alert("系统繁忙！");
           					 }
						});
						<!--$('tbody input[type=checkbox]:checked').parents("tr").remove();-->
						$("thead input[type='checkbox']").prop("checked", true).click();
					}
			});
		});
        </script>
	</body>

</html>